package com.xk.controller;

import com.xk.pojo.Classes;
import com.xk.pojo.Page;
import com.xk.pojo.Teacher;
import com.xk.service.ClassesService;
import com.xk.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/class")
public class ClassesController {
    @Autowired
    private ClassesService classesService;

    @RequestMapping("/getAllClasses")
    @ResponseBody
    public List<Classes> getAllClasses(){
        List<Classes> allClasses = classesService.getAllClasses();
        return allClasses;
    }

    @RequestMapping("/deleteClassById")
    @ResponseBody
    public String deleteClassById(Integer classID){
        System.out.println("delete");
        classesService.deleteClassById(classID);
        return "aa";
    }

    @RequestMapping("/updateClassById")
    @ResponseBody
    public int updateClassById(Classes classes){
        int i = classesService.updateClassesById(classes);
        if (i==-1)
            System.out.println("更新失败，重复班主任");
        return i;
    }
    @RequestMapping("/addClass")
    @ResponseBody
    public String addClass(Classes classes){
        String msg = classesService.addClass(classes);
        return msg;
    }
    @RequestMapping("/getClassesListByPage")
    @ResponseBody
    public Page<Classes> getClassesListByPage(int pageNumber, int pageSize,String search ){
        System.out.println("controller"+search);
        Page<Classes> page = classesService.getClassesListByPage(pageNumber, pageSize,search);
        return page;
    }


}
